import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CustomTable extends StatelessWidget {
  final String ?text;

  CustomTable({this.text}) : super();

  @override
  Widget build(BuildContext context) {
    var title = _ItemBean("单位称", "量纲", "单位", "单位名称", "单位符号");
    var m = _ItemBean("长度", "L", "1m", "米", "m");
    var kg = _ItemBean("质量", "M", "1Kg", "千克", "Kg");
    var s = _ItemBean("时间", "T", "1s", "秒", "s");
    var a = _ItemBean("安培", "Ι", "1A", "安培", "A");
    var k = _ItemBean("热力学温度", "θ", "1K", "开尔文", "K");
    var mol = _ItemBean("物质的量", "N", "1mol", "摩尔", "mol");
    var cd = _ItemBean("发光强度", "J", "1cd", "坎德拉", "cd");

    var data = <_ItemBean>[title, m, kg, s, a, k, mol, cd];

    return Scaffold(
      appBar: AppBar(title: Text("TabRow表格"),),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Container(
          padding: EdgeInsets.only(top: 15),
          child: Center(
            child: Table(
              //每行宽度
              columnWidths: const <int, TableColumnWidth>{
                0: FixedColumnWidth(80.0),
                1: FixedColumnWidth(65.0),
                2: FixedColumnWidth(70.0),
                3: FixedColumnWidth(70.0),
                4: FixedColumnWidth(65.0),
              },
              defaultVerticalAlignment: TableCellVerticalAlignment.middle,
              //方框线
              border: TableBorder.all(
                  color: Colors.orangeAccent, width: 1.0, style: BorderStyle.solid),
              children: data
                  .map((item) => TableRow(children: <Widget>[
                Center(
                    child: Text(
                      item.name,
                      style: TextStyle(color: Colors.blue,fontSize: 15),
                    )),
                Padding(
                  padding: const EdgeInsets.all(5.0),
                  child: Center(child: Text(item.symbol,style:TextStyle(fontSize: 15) ,)),
                ),
                Padding(
                  padding: const EdgeInsets.all(5.0),
                  child: Center(child: Text(item.unitSymbol,style:TextStyle(fontSize: 15))),
                ),
                Padding(
                  padding: const EdgeInsets.all(5.0),
                  child: Center(child: Text(item.unitName,style:TextStyle(fontSize: 15))),
                ),
                Padding(
                  padding: const EdgeInsets.all(5.0),
                  child: Center(child: Text(item.unit,style:TextStyle(fontSize: 15))),
                ),
              ]))
                  .toList(),
            ),
          ),
        ),
      ),
    );
  }
}

class _ItemBean {
  String name;
  String symbol;
  String unit;
  String unitName;
  String unitSymbol;

  _ItemBean(this.name, this.symbol, this.unit, this.unitName, this.unitSymbol);
}
